﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Sales_DrawPrint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            ZSql zsql = new ZSql();
            hfgetid.Value = Server.UrlDecode(Request.Cookies["user"].Values["name"]);
            string WageId = Request.QueryString["WageId"].ToString();

           
                if (WageId == "All")
                {
                    string sql = "select Deptid,WStaffId,WStaffSalary,WStaffName,sum (WSWage) as daytol,WageDate,department from CS_Wages,Department where department=Deptname group by WStaffName,Deptid,WStaffId,department,WageDate,WStaffSalary  ";
                    zsql.Open(sql);
                }
                if (WageId == "tj")
                {
                    string gettim1 = Request.QueryString["gettim1"].ToString();
                    string gettim2 = Request.QueryString["gettim2"].ToString();
                    string name = Request.QueryString["name"].ToString();
                    string selectId = Request.QueryString["selectId"].ToString();
                    string sql = "select Deptid,WStaffId,WStaffSalary,WStaffName,sum (WSWage) as daytol,WageDate,department from CS_Wages,Department where department=Deptname";
                    string group = "group by WStaffName,Deptid,WStaffId,department,WageDate,WStaffSalary";
                    if (gettim1 != "" && gettim2 != "")
                    {

                        sql += " and WageDate >='" + gettim1 + "' and WageDate <='" + gettim2 + "'";
                        sql += group;
                        zsql.Open(sql);
                    }
                    if (name != "")
                    {

                        sql += " and WStaffName='" + name + "' ";
                        sql += group;
                        zsql.Open(sql);
                    }
                    if (selectId != "0")
                    {
                        sql += " and Deptid=" + selectId + " ";
                        sql += group;
                        zsql.Open(sql);
                    }
                    if (gettim1 != "" && gettim2 != "" && name != "")
                    {
                        sql += " and WageDate >='" + gettim1 + "' and WageDate <='" + gettim2 + "' and WStaffName='" + name + "'";
                        sql += group;
                        zsql.Open(sql);

                    }
                    if (gettim1 != "" && gettim2 != "" && selectId != "0")
                    {
                        sql += " and Deptid=" + selectId + " and WageDate >='" + gettim1 + "' and WageDate <='" + gettim2 + "' ";
                        sql += group;
                        zsql.Open(sql);
                    }
                    if (selectId != "0" && name != "")
                    {
                        sql += " and Deptid=" + selectId + " and WStaffName='" + name + "'";
                        sql += group;
                        zsql.Open(sql);
                    }
                    if (gettim1 != "" && gettim2 != "" && name != "" && selectId != "0")
                    {
                        sql += " and Deptid=" + selectId + " and WStaffName='" + name + "' and WageDate >='" + gettim1 + "' and WageDate <='" + gettim2 + "'";
                        sql += group;
                        zsql.Open(sql);
                    }
                }

                DataTable dt = new DataTable();
                string strTable = "";
                dt = zsql.m_table;
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        strTable += "<div align=\"center\" style=\"width: 97%; font-size: 24px; font-weight: bolder; margin-bottom: 7px;\">员工工资单</div>";
                        strTable += "<table style=\"width: 97%;text-align:center;\" class=\"normal\">";

                        strTable += "<tr height=\"30px\"><td width=\"12%\">员工姓名</td><td width=\"9%\">所属部门</td><td width=\"9%\">基本工资</td><td width=\"10%\">该天工资</td><td width=\"10%\">业绩日期</td></tr>";
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {





                            strTable += "<tr><td>" + zsql.m_table.Rows[i]["WStaffName"].ToString() + "</td><td>" + zsql.m_table.Rows[i]["department"].ToString() + "</td><td>" + zsql.m_table.Rows[i]["WStaffSalary"].ToString().Substring(0, zsql.m_table.Rows[i]["WStaffSalary"].ToString().Length - 2) + "元</td><td>" + zsql.m_table.Rows[i]["daytol"].ToString().Substring(0, zsql.m_table.Rows[i]["daytol"].ToString().Length - 2) + "元</td><td>" + zsql.m_table.Rows[i]["WageDate"].ToString() + "</td></tr>";

                           


                        }
                        strTable += "</table>";
                        strTable += "<table style=\"width: 97%;text-align:center;\" class=\"normal\"><tr><td width=\"24%\">操作时间：</td><td width=\"36%\">" + DateTime.Now.ToString() + "</td><td width=\"20%\">操作员：</td><td>" + hfgetid.Value + "</td></tr></table>";
                        zsql.Close();

                        lblTable.Text = strTable;
                    }
                }


            }
        }
    
}
